package edu.bw.web.role;

import cn.hutool.json.JSONUtil;
import edu.bw.common.CommonResult;
import edu.bw.dto.UpdateRoleForm;
import edu.bw.service.RoleService;
import edu.bw.service.impl.RoleServiceImpl;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet("/role/update")
public class UpdateServlet extends HttpServlet {
    RoleService roleService=new RoleServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String reqJSON = request.getReader().readLine();
        //{id: 13, roleName: "测试111", permissions: [1, 2, 4, 6, 31, 32], desc: "测试1sdhs", changed: true}
        UpdateRoleForm updateRoleForm = JSONUtil.toBean(reqJSON, UpdateRoleForm.class);

        Integer rows=roleService.update(updateRoleForm);

        response.getWriter().write(JSONUtil.toJsonStr(CommonResult.ok().put("rows",rows)));

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
